from api.Add_address import add_address
from api.Add_shoppingCart import add_shoppingCart
from api.login import *
import config
import requests

from api.settlement_goods import settlement_goods
from api.submit_order import submit_order
from common.utils import assert_common

# 1.登录
response = login(config.username, config.password)
print(response.json())
token = response.json().get('data').get('token')
print(token)
assert_common(response)

# 2.搜索商品
search_url = f'{config.URL}/wx/goods/list?keyword=母亲节&page=1&limit=10&categoryId=0'
response=requests.get(url=search_url)
goodsId = response.json().get('data').get('list')[0].get('id')
# 3.获取商品信息
search_goods_url=f'{config.URL}/wx/goods/detail?id=1181000'
requests.get(url=search_goods_url)
assert_common(response)


# 4.获取购物车商品数量
search_shoppingCart_url = f'{config.URL}/wx/cart/goodscount'
response=requests.get(url=search_shoppingCart_url, headers={'X-Litemall-Token': token})
print(response.json())
assert_common(response)


# 5.加入购物车
response = add_shoppingCart(token,goodsId=1181000, number=5, productId=2)
print(response.json())
assert_common(response)


# 6.查看购物车
look_shoppingCart_url = f'{config.URL}/wx/cart/index'
response = requests.get(url=look_shoppingCart_url, headers={'X-Litemall-Token': token})
print(response.json())
assert_common(response)


# 7.选中商品
select_goods_url = f'{config.URL}/wx/cart/checked'
headers_data = {
    'X-Litemall-Token': token,
    'Content-Type': 'application/json'
}
test_data = {"productIds":[232,31],"isChecked":1}
response = requests.post(url=select_goods_url, headers=headers_data, json=test_data)
print(response.json())
assert_common(response)



# 8.结算商品
response =settlement_goods(token)
print(response.json())
assert_common(response)



# 9.添加地址
response=add_address(token, name='jack001', tel='13611224455', country='China', province='Beijing',city='Beijing',county='HaiDian',areaCode='110101',postalCode='100091',addressDetail='heima',isDefault='true')
print(response.json())
assert_common(response)



# 10.查看地址
look_address_url = f'{config.URL}/wx/address/list'
response = requests.get(url=look_address_url, headers={'X-Litemall-Token': token})
print(response.json())
assert_common(response)



# 11.提交订单
response = submit_order(token)
print(response.json())
assert_common(response)



# 12.查看订单
show_order_url = f'{config.URL}/wx/order/list?showType=0&page=1&limit=10'
response = requests.get(url=show_order_url, headers={'X-Litemall-Token': token})
print(response.json())
assert_common(response)
